/*******************************************************************************
 * Copyright (c) 2006 CEA List.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     CEA List - initial API and implementation
 *******************************************************************************/
package com.cea.papyrus.diagram.activity.editpart;

import org.eclipse.draw2d.IFigure;
import org.eclipse.uml2.uml.Element;
import org.eclipse.uml2.uml.ValueSpecification;

import com.cea.papyrus.core.editor.ModelManager;
import com.cea.papyrus.core.editpart.LinkNameDisplayEditPart;
import com.cea.papyrus.core.figures.StringFigure;
import com.cea.papyrus.diagraminterchange2.di2.GraphNode;

/**
 * Manages display of Guards
 *
 * @author Gilles Cannenterre
 * @since 4 avr. 07
 */
public class GuardStringDisplayEditPart extends LinkNameDisplayEditPart {	

	/** The guard text. */
	private String literalStringText;
	
	public GuardStringDisplayEditPart(GraphNode graphNode, ModelManager modelManager) {
		super(graphNode,modelManager);
		element = null;
		literalStringText = "";
	}

	public GuardStringDisplayEditPart(GraphNode graphNode,Element element,ModelManager modelManager) {
		super(graphNode,modelManager);
		this.element = element;
		literalStringText = "";
	}
	
	/* (non-Javadoc)
	 * @see com.cea.papyrus.core.common.editpart.GraphNodeWithSemanticEditPart#createFigure()
	 */
	@Override
	protected IFigure createFigure() {
		if ((element != null )&&(element instanceof ValueSpecification)) {
			ValueSpecification literalString = (ValueSpecification) element;
			if (literalString.stringValue() == null) {
				literalStringText = "";
			} else {
				literalStringText = literalString.stringValue();
			}
			return new StringFigure("[ "+literalString.stringValue()+" ]");
		} else {
			return new StringFigure("[ ]");
		}
	}
	
	/* (non-Javadoc)
	 * @see com.cea.papyrus.core.common.editpart.GraphNodeWithSemanticEditPart#refreshVisuals()
	 */
	@Override
	protected void refreshVisuals() {
		StringFigure f = (StringFigure)getFigure();
		if ((element != null )&&(element instanceof ValueSpecification)) {
			ValueSpecification literalString = (ValueSpecification) element;
			if (literalString.stringValue() == null) {
				literalStringText = "[ ]";
			} else {
				literalStringText = "[ "+literalString.stringValue()+" ]";
			}
			f.setText(literalStringText);
		} else {
			f.setText("");
		}
		f.setVisible(isVisible());
	}
}